[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

function Write-Log() {
    param(
        [string] $msg,
        [Parameter(Mandatory = $False)] [bool] $expand = $False
    )
    if ($expand) {
        Write-Output "+++ $($msg)"
    }
    else {
        Write-Output "--- $($msg)"
    }
}

function Start-Event() {
    param(
        [string] $event_name,
        [string] $event_parent
    )

    # Start this tracing span.
    Start-Process -NoNewWindow "imp-ci" -ArgumentList @(`
            "events", "new", `
            "--name", "$($event_name)", `
            "--child-of", "$($event_parent)"
    ) | Out-Null

    Write-Log "$($event_name)"
}

function Finish-Event() {
    param(
        [string] $event_name,
        [string] $event_parent
    )

    # Emit the end marker for this tracing span.
    Start-Process -NoNewWindow "imp-ci"  -ArgumentList @(`
            "events", "new", `
            "--name", "$($event_name)", `
            "--child-of", "$($event_parent)"
    ) | Out-Null
}

function Stop-Runtime() {
    & spatial "service" "stop"
    Stop-Process -Name "java" -Force -ErrorAction SilentlyContinue
}

$ErrorActionPreference = 'Stop'
